#include <iostream>

// 基类
class Base {
public:
    Base() { std::cout << "Base constructor" << std::endl; }
    virtual ~Base() { std::cout << "Base destructor" << std::endl; }
};

// 派生类
class Derived : public Base {
public:
    Derived() { std::cout << "Derived constructor" << std::endl; }
    ~Derived() override { std::cout << "Derived destructor" << std::endl; }
};

int main() {
    Base* ptr = new Derived();  // 通过基类指针指向派生类对象
    delete ptr;  // 由于基类析构函数是虚函数，会先调用派生类析构函数，再调用基类析构函数
    return 0;
}